package com.angis.fx.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.angis.fx.activity.R;

public class ImageAdapter  extends BaseAdapter{
	private Bitmap[] image;
	private Context context;
	private LayoutInflater mInflater;
	
	public void setImage(Bitmap[] image) {
		this.image = image;
	}

	public ImageAdapter(Bitmap[] image, Context context) {
		super();
		this.image = image;
		this.context = context;
		mInflater = (LayoutInflater) context
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return image.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return image[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageHolder holder=null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.image_item, null);
			holder = new ImageHolder();
			holder.appImage = (ImageView) convertView
					.findViewById(R.id.image_item);
			convertView.setTag(holder);

		} else { 
			holder = (ImageHolder) convertView.getTag();

		}
		if (image[position] != null) {
			holder.appImage.setImageBitmap(image[position]);
		}
		return convertView;
	}
	private class ImageHolder {
		ImageView appImage;
	}
}
